
package com.cmc.dao.hibernate;

import java.util.List;

import com.cmc.dao.hibernate.BaseDaoHibernate;
import com.cmc.model.GroupSetting;
import com.cmc.dao.GroupSettingDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class GroupSettingDaoHibernate extends BaseDaoHibernate implements GroupSettingDao {

    /**
     * @see com.cmc.dao.GroupSettingDao#getGroupSettings(com.cmc.model.GroupSetting)
     */
    public List getGroupSettings(final GroupSetting groupSetting) {
        return getHibernateTemplate().find("from GroupSetting");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.
        if (groupSetting == null) {
            return getHibernateTemplate().find("from GroupSetting");
        } else {
            // filter on properties set in the groupSetting
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(groupSetting).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(GroupSetting.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }*/
    }

    /**
     * @see com.cmc.dao.GroupSettingDao#getGroupSetting(Long id)
     */
    public GroupSetting getGroupSetting(final Long id) {
        GroupSetting groupSetting = (GroupSetting) getHibernateTemplate().get(GroupSetting.class, id);
        if (groupSetting == null) {
            log.warn("uh oh, groupSetting with id '" + id + "' not found...");
            throw new ObjectRetrievalFailureException(GroupSetting.class, id);
        }

        return groupSetting;
    }

    /**
     * @see com.cmc.dao.GroupSettingDao#saveGroupSetting(GroupSetting groupSetting)
     */    
    public void saveGroupSetting(final GroupSetting groupSetting) {
        getHibernateTemplate().saveOrUpdate(groupSetting);
    }

    /**
     * @see com.cmc.dao.GroupSettingDao#removeGroupSetting(Long id)
     */
    public void removeGroupSetting(final Long id) {
        getHibernateTemplate().delete(getGroupSetting(id));
    }
}
